// 处理文章列表获取
import ajax from '../utils/request'

/**
 *
 * @param {*} channelId 频道id
 * @param {*} timestamp 时间戳
 * @returns
 */
export const getArticles = (channelId, timestamp) => {
  return ajax({
    url: '/app/v1_1/articles',
    method: 'GET',
    params: {
      channel_id: channelId,
      timestamp: timestamp, // 时间戳，请求新的推荐数据传当前的时间戳，请求历史推荐传指定的时间戳
      with_top: 1
    }
  })
}

/**
 * 不喜欢的文章
 * @param {*} articleId 文章编号
 * @returns
 */
export const unLike = (articleId) => {
  return ajax({
    url: '/app/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target: articleId
    }
  })
}

/**
 * 举报文章
 * @param {*} articleId 文章编号
 * @param {*} reportTypeId 举报类型
 * @returns
 */
export const report = (articleId, reportTypeId) => {
  return ajax({
    url: '/app/v1_0/article/reports',
    method: 'POST',
    data: {
      target: articleId,
      type: reportTypeId
    }
  })
}

/**
 * 获取文章详情
 * @param {*} articleId  文章id
 * @returns
 */
export const getDetail = (articleId) => {
  return ajax({
    url: '/app/v1_0/articles/' + articleId,
    method: 'GET'
  })
}

/**
 * 取消点赞
 * @param {*} id 文章编号
 */
export const deleteLike = id => {
  return ajax({
    method: 'DELETE',
    url: '/app/v1_0/article/likings/' + id
  })
}

/**
 * 添加点赞
 * @param {*} id 文章编号
 */
export const addLike = id => {
  return ajax({
    method: 'POST',
    url: '/app/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

/**
 * 取消不喜欢
 * @param {*} id 文章编号
 */
export const deleteDisLike = id => {
  return ajax({
    method: 'DELETE',
    url: '/app/v1_0/article/dislikes/' + id
  })
}

/**
 * 添加不喜欢
 * @param {*} id 文章编号
 */
export const addDisLike = id => {
  return ajax({
    method: 'POST',
    url: '/app/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}
